/*
 * @Author: jawen jawen.9@outlook.com
 * @Date: 2025-05-30 18:07:47
 * @LastEditors: jawen jawen.9@outlook.com
 * @LastEditTime: 2025-07-21 16:26:55
 * @FilePath: \yujn\src\composables\useTheme.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { ref, watch } from 'vue'
import { useLocalStorage } from '@vueuse/core'

export function useTheme() {
    const theme = useLocalStorage('theme', 'light')

    const toggleTheme = () => {
        theme.value = theme.value === 'light' ? 'dark' : 'light'
    }

    watch(theme, (newTheme) => {
        document.documentElement.classList.toggle('dark', newTheme === 'dark')
    }, { immediate: true })

    return {
        theme,
        toggleTheme
    }
}